package com.example.gif_recycle_view_probe;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;

import java.util.List;

public class GifAdapter extends RecyclerView.Adapter<GifAdapter.GifViewHolder> {
    private List<Integer> gifList;


    public GifAdapter(List<Integer> list) {
        gifList = list;
    }


    @NonNull
    @Override
    public GifViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

        // Holder持有gif_item layout
        View view = LayoutInflater
                .from(parent.getContext()).
                inflate(R.layout.gif_item, parent, false);
        return new GifViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull GifViewHolder holder, int position) {
        Glide.with(holder.gifImageView).asGif()
                .load(gifList.get(position))
                .into(holder.gifImageView);
    }

    @Override
    public int getItemCount() {
        return gifList.size();
    }

    static class GifViewHolder extends RecyclerView.ViewHolder {
        ImageView gifImageView;

        public GifViewHolder(@NonNull View itemView) {
            super(itemView);
            gifImageView = itemView.findViewById(R.id.gifImageView);
        }


    }

}
